<?php

namespace app\common\model\plus\coupon;

//use think\Hook;
use app\common\model\BaseModel;

/**
 * 用户推广优惠券模型
 */
class UserPromoterCoupon extends BaseModel
{
    protected $name = 'user_promoter_coupon';
    protected $pk = 'user_promoter_coupon_id';

    /**
     * 关联用户表
     */
    public function user()
    {
        return $this->belongsTo('app\common\model\user\User');
    }

    /**
     * 关联优惠券表
     */
    public function coupon()
    {
        return $this->belongsTo('app\common\model\plus\coupon\Coupon');
    }

    /**
     * 添加发放记录
     */
    public function add($referee_id, $coupon_id, $user_id)
    {
        // 整理数据
        $data = [
            'coupon_id'  => $coupon_id,
            'user_id'    => $user_id,
            'app_id'     => self::$app_id,
            'referee_id' => $referee_id
        ];
        return $this->save($data);
    }

    public static function checkgetcoupon($uid,$reid){
        if(self::where(['user_id'=>$uid])->where(['referee_id'=>$reid])->count()){
            return true;
        }
        return false;
    }
}